package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallDataCountReadDao;
import com.party.core.dao.write.mall.MallDataCountWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallDataCount;
import com.party.core.model.mall.MallDataCountWithMember;
import com.party.core.service.mall.IMallDataCountService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class MallDataCountService implements IMallDataCountService {

    @Autowired
    private MallDataCountReadDao mallDataCountReadDao;

    @Autowired
    private MallDataCountWriteDao mallDataCountWriteDao;

    @Override
    public String insert(MallDataCount mallDataCount) {
        BaseModel.preInsert(mallDataCount);
        boolean result = mallDataCountWriteDao.insert(mallDataCount);
        if(result){
            return mallDataCount.getId();
        }
        return mallDataCount.getId();
    }

    @Override
    public boolean update(MallDataCount mallDataCount) {
        mallDataCount.setUpdateDate(new Date());
        return mallDataCountWriteDao.update(mallDataCount);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallDataCountWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallDataCountWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return mallDataCountWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallDataCountWriteDao.batchDelete(ids);
    }

    @Override
    public MallDataCount get(String id) {
        return mallDataCountReadDao.get(id);
    }

    @Override
    public List<MallDataCount> listPage(MallDataCount mallDataCount, Page page) {
        return mallDataCountReadDao.listPage(mallDataCount, page);
    }

    @Override
    public List<MallDataCount> list(MallDataCount mallDataCount) {
        return listPage(mallDataCount, null);
    }

    @Override
    public List<MallDataCount> batchList(Set<String> ids, MallDataCount mallDataCount, Page page) {
        return null;
    }

    @Override
    public List<MallDataCountWithMember> webListPage(MallDataCountWithMember mallDataCountWithMember, Map<String, Object> params, Page page) {
        return mallDataCountReadDao.webListPage(mallDataCountWithMember, params, page);
    }

    @Override
    public List<MallDataCountWithMember> webListPageQuery(MallDataCountWithMember mallDataCountWithMember, Map<String, Object> params, Page page) {
        return mallDataCountReadDao.webListPageQuery(mallDataCountWithMember, params, page);
    }

    /**
     * 获取统计数
     * @return
     */
    @Override
    public Map<String, Object> getStatistics() {
        return mallDataCountReadDao.getStatistics();
    }

    @Override
    public MallDataCount findByMemberId(String memberId) {
        return mallDataCountReadDao.findByMemberId(memberId);
    }
}
